package com.groupseven.happycampus.controller;

import com.groupseven.happycampus.common.pojo.Seat;
import com.groupseven.happycampus.common.pojo.Student;

import com.groupseven.happycampus.common.result.R;
import com.groupseven.happycampus.common.vo.*;
import com.groupseven.happycampus.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Map;

/**
 * @CreateTime: 2022-07-26 11:15
 * @author: bestzqw
 * @Description:
 */
@RestController
@RequestMapping("/library/seat")
public class SeatController {

    @Autowired
    private SubscribeService subscribeService;

    @RequestMapping("/list")
    //RequestParam 必须加此 注解 否则无法接受到
    public LayuiPageVo<Seat> listSeat(@RequestParam Map<String,String> parms){
        System.out.println(parms);
        return subscribeService.seatList(parms);
    }


    @RequestMapping("/update")
    public R updateSeat (Seat seat){

        System.out.println(seat);

        int i = subscribeService.updateSeat(seat);

        if (i > 0){
            return R.ok();
        } else {
            return R.error();
        }

    }


    @RequestMapping("/gradePie")
    public R echartsPie()  {
        List<GradePie> list   = subscribeService.selectByGradePie();
        return R.ok().data("list",list);
    }


    // 根据地址分组查询，并将结果封装到 AddressBar 这个类中
    @RequestMapping("/sexBar")
    public R echartBar()  {
        List<SexBar> list   = subscribeService.selectBySexBar();
        return R.ok().data("list",list);
    }


    @RequestMapping("/studentList")
    public LayuiPageVo<Student> listStudent(@RequestParam Map<String,String> parms){
        System.out.println(parms);
        return subscribeService.listStudent(parms);
    }


    @RequestMapping("/groupRoom")
    public R groupByRoom(){   //将查询到的roomId 的list集合放在R中
       List<SelectRoomVo> list = subscribeService.groupByRoom();

        return R.ok().data("list",list);
    }


    @RequestMapping("/studentAdd")
    public R addStudent( Student student){   //将查询到的roomId 的list集合放在R中
        System.out.println(student);
        student.setStatus(false);
        int i = subscribeService.addStudent(student);

        if (i > 0){
            return R.ok();
        } else {
            return R.error().message("该教室已满，请换一间教室吧");
        }
    }


    @RequestMapping("/arrive")
    public R statusStudent1(Integer id){   //将查询到的roomId 的list集合放在R中

        int i = subscribeService.updateStudentStatus(id,true);
        if (i > 0){
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping("/goaway")
    public R statusStudent2(Integer id){   //将查询到的roomId 的list集合放在R中

        int i = subscribeService.updateStudentStatus(id,false);
        if (i > 0){
            return R.ok();
        } else {
            return R.error();
        }
    }


    // 根据地址分组查询，并将结果封装到 AddressBar 这个类中
    @RequestMapping("/statusbar")
    public R studentBar()  {
        List<StudentStatusBarVo> list   = subscribeService.selectByStudentStatus();
        return R.ok().data("list",list);
    }




}
